package com.ayne.network.server.listener;

import com.ayne.network.packets.Packet.Packet0LoginRequest;
import com.ayne.network.packets.Packet.Packet1LoginResponse;
import com.ayne.network.packets.Packet.Packet2Message;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.minlog.Log;

public class NetworkListener extends Listener {

	@Override
	public void connected(Connection conn) {
		Log.info(conn.getRemoteAddressTCP() + " connected.");
	}

	@Override
	public void disconnected(Connection conn) {
		Log.info(conn.getRemoteAddressTCP() + " disconnected.");
	}

	@Override
	public void received(Connection conn, Object obj) {
		if (obj instanceof Packet0LoginRequest) {
			Packet1LoginResponse loginResponse = new Packet1LoginResponse();
			loginResponse.accepted = true;
			conn.sendTCP(loginResponse);
			return;
		}
		if (obj instanceof Packet2Message) {
			String message = ((Packet2Message) obj).message;
			Log.info(message);
			return;
		}
	}
}
